package com.game.grid;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import com.mcodesal.framework.ResourceProvider;
import com.mcodesal.framework.Sprite2D;
import com.mcodesal.framework.ResourceProvider.Texture;


/**
 * This class adds one more layer above our LabelMaker class so that
 * we now just make one call in our GameRenderer class to render all the GUI.
 * 
 * @author Matias
 *
 */
public class MainMenu {

	private Sprite2D startButton;
	private Sprite2D title;
	private Sprite2D optionsButton;
	private Sprite2D helpButton;
	private Sprite2D creditsButton;
	private Sprite2D hiScoresButton;
	private int BUTTON_OFFSET = 10;
	private ArrayList<Sprite2D> buttons;
	private int width = 450;//300; midsize
	private int height = 75;//50; midsize
	
	public MainMenu() {
		buttons = new ArrayList<Sprite2D>();
		
		//title = new Sprite2D(320, 160); midsize
		title = new Sprite2D(480, 240);
		title.setFrameClip(0, 0, 320f/512f, 160f/256f);
		title.setTexture(ResourceProvider.getInstance().getTexture(Texture.MENU_TITLE));
		title.x = 0;
		title.y = 0;
		startButton = new Sprite2D(width, height);
		startButton.setFrameClip(0, 0, 305f/512f, 51f/64f);
		startButton.setTexture(ResourceProvider.getInstance().getTexture(Texture.STARTGAME));
		buttons.add(startButton);
		optionsButton = new Sprite2D(width, height);
		optionsButton.setFrameClip(0, 0, 305f/512f, 51f/64f);
		optionsButton.setTexture(ResourceProvider.getInstance().getTexture(Texture.OPTIONS));
		buttons.add(optionsButton);
		hiScoresButton = new Sprite2D(width, height);
		hiScoresButton.setFrameClip(0, 0, 305f/512f, 51f/64f);
		hiScoresButton.setTexture(ResourceProvider.getInstance().getTexture(Texture.HIGHSCORES));
		buttons.add(hiScoresButton);
		helpButton = new Sprite2D(width, height);
		helpButton.setFrameClip(0, 0, 305f/512f, 51f/64f);
		helpButton.setTexture(ResourceProvider.getInstance().getTexture(Texture.HELP));
		buttons.add(helpButton);
		creditsButton = new Sprite2D(width, height);
		creditsButton.setFrameClip(0, 0, 305f/512f, 51f/64f);
		creditsButton.setTexture(ResourceProvider.getInstance().getTexture(Texture.CREDITS));
		buttons.add(creditsButton);
		
		for(int i = 0; i < buttons.size(); i++) {
			buttons.get(i).y = title.height+BUTTON_OFFSET*i+buttons.get(i).height*i;
		}
	}
	/**
	 * Goes inside onSurfaceChanged method in our GameRenderer.
	 * @param gl
	 */
	public void initialize(GL10 gl, int width, int height) {

        
	}
	
	public void draw(GL10 gl) {
		
		gl.glPushMatrix();
        gl.glTranslatef(title.x, title.y, 0);
		title.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(startButton.x, startButton.y, 0);
		startButton.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(startButton.x, startButton.y, 0);
		startButton.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(optionsButton.x, optionsButton.y, 0);
		optionsButton.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(hiScoresButton.x, hiScoresButton.y, 0);
		hiScoresButton.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(helpButton.x, helpButton.y, 0);
		helpButton.draw(gl);
		gl.glPopMatrix();
		
		gl.glPushMatrix();
        gl.glTranslatef(creditsButton.x, creditsButton.y, 0);
		creditsButton.draw(gl);
		gl.glPopMatrix();
	}
}
